<template>
  <el-container class="home-container">
    <!--头部区域-->
    <el-header class="header">
      <div class="header-left">
          <el-tooltip class="item" effect="dark" content="点击Logo   侧边栏缩放" placement="bottom-start">
                 <img @click="isCollapse = !isCollapse" class="logo" src="https://liyun-oss1.oss-cn-beijing.aliyuncs.com/superb-class/image/assets/image/youzi1.jpg?versionId=CAEQGBiBgMCd1vyZ5hciIGU3OWI1ZGJhMzllMDQ5ZTRiY2FhZmFmZDY0MjhiOGM5" />
        </el-tooltip>
        <span>小柚智汇</span>
      </div>
      <el-menu
        router
        class="el-menu-demo"
        mode="horizontal"
        text-color="orange"
        active-text-color="orange"
      >
        <el-submenu index="2">
          <template slot="title">
            <el-badge value="new" class="item" :hidden="!isNewMesg">
              <el-menu-item index="/page/message/sign" @click="delNewtitle"  title="消息中心">
                  <i class="menu-i el-icon-message-solid"></i>
              </el-menu-item>
            </el-badge>
          </template>
          <el-badge value="new" class="item" :hidden="!isNewMesg">
          <el-menu-item index="/page/message/sign" @click="delNewtitle">签到</el-menu-item>
            </el-badge>
          <el-menu-item index="/page/message/notice">通知</el-menu-item>
          <el-menu-item index="/page/message/otherMessage">其他消息</el-menu-item>
        </el-submenu>

        <el-submenu index="">
          <template slot="title">
            <img  v-if="progressFlag" class="avatar" :src="user.userPic" />
            <span
            class="text-avatar"
            v-if="!progressFlag"
            >{{avaentText}}
          </span>
            <span class="nickName">{{user.nickname}}</span>
            </template>
          <el-menu-item index="/page/mine/passphone">个人中心</el-menu-item>
          <el-menu-item @click.native="logout">退出</el-menu-item>
        </el-submenu>

      </el-menu>
    </el-header>
    <!--页面主体区域-->
    <el-container>
      <!--侧边栏-->
      <el-aside  width="auto"  class="aside-menu">
        <app-aside :is-collapse="isCollapse"></app-aside>
      </el-aside>
      <!--右侧内容-->
      <el-main style="height:calc(100vh);flex-grow:1;">
        <transition   name="component-fade" mode="out-in" >
          <router-view></router-view>
        </transition>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import AppAside from '@/componets/aside'
import { getUserProfile } from '@/utils/api/user.js'
// import { AllSign } from '@/utils/api/sign.js'
export default {
  name: '',
  props: {},
  components: {
    AppAside
  },
  data () {
    return {
      isCollapse: false, // 侧边栏的展示状态
      user: {}, // 当前登录用户信息
      avaentText: '', // 文字头像信息
      progressFlag: true, // 头像按需展示
      lastLength: 0,
      isNewMesg: false, // 是否有新消息\
      transitionName: ''
    }
  },
  created () {
    this.loadUserProfile() // 页面加载就初始化这个函数
  },
  methods: {
    loadUserProfile () {
      getUserProfile().then(res => {
        this.user = res.data.data
        this.IsAvaent()
      })
    },
    logout () {
      this.$confirm('确认退出吗？', '退出提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          // 清除用户登录状态
          window.sessionStorage.removeItem('user')
          // 跳转到登录页面
          this.$router.push('/login')
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消退出'
          })
        })
    },
    // 判断是否有头像,若无展示文字头像
    IsAvaent () {
      if (this.user.userPic === null) {
        this.progressFlag = false
        var textName = this.user.nickname || this.user.username
        this.avaentText = textName.slice(-2).toUpperCase()
      } else { this.progressFlag = true }
    },
    delNewtitle () {
      this.isNewMesg = false
    }
  }
}
</script>

<style lang="less" scoped>
.el-footer {
    background-color:#eee;
    text-align: center;
    line-height: 40px;
    font-size: 15px;
  }
/deep/.el-main{
  padding-top: 15px ;
  padding-left: 10px;
  background-color: transparent!important;
  background-size: cover;
    animation: fade-in;/*动画名称*/
    animation-duration: 0.5s;/*动画持续时间*/
    -webkit-animation:fade-in 0.5s;/*针对webkit内核*/
}
@keyframes fade-in {
    0% {opacity: 0;}/*初始状态 透明度为0*/
    40% {opacity: 0;}/*过渡状态 透明度为0*/
    100% {opacity: 1;}/*结束状态 透明度为1*/
}
@-webkit-keyframes fade-in {/*针对webkit内核*/
    0% {opacity: 0;}
    40% {opacity: 0;}
    100% {opacity: 1;}
}

.home-container {
  background: url('https://liyun-oss1.oss-cn-beijing.aliyuncs.com/superb-class/image/assets/image/shiguang.png?versionId=CAEQGBiBgICq3PyZ5hciIDkwNzNmNGFlOTcyNjRhODg4OWI1ZDU3ZjE1ZmM5Mzhk') no-repeat;

  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
   /deep/.el-submenu .el-menu-item{
    min-width: 130px;
    padding: 0s;
  }
  .aside-menu {
    margin-top: 1.2%;
    border-radius: 5px;
    margin-left: 10px;
        height: 82%;
    animation: fade-in;/*动画名称*/
    animation-duration: 0.5s;/*动画持续时间*/
    -webkit-animation:fade-in 0.5s;/*针对webkit内核*/
  -moz-box-shadow: 2px 2px 10px #909090;/*firefox*/
    -webkit-box-shadow: 2px 2px 10px #909090;/*safari或chrome*/
    box-shadow:2px 2px 10px #909090;/*opera或ie9*/
    }
    .aside-menu:hover{
     box-shadow: inset -6px -6px 10px #c78534,
                    inset 6px 6px 20px rgba(0, 0, 0, 0.05);
                transform: scale(0.95);
                cursor: pointer;
                transition: all 0.2s linear;
  -moz-box-shadow: 2px 2px 10px #909090;/*firefox*/
    -webkit-box-shadow: 2px 2px 10px #909090;/*safari或chrome*/
    box-shadow:2px 2px 10px #909090;/*opera或ie9*/

}
}
.header {
  height: 60px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 25px;
  background-color: #fff;
  box-shadow: 0 0 15px #ddd;
  .header-left {
    display: flex;
    justify-content: space-between;
    img:hover{
      color: #000;
      cursor: pointer;
    }
    .logo {
      width: 50px;
      height: 50px;
      border-radius: 50%;
      margin-top: 5px;
    }
    span {
      font-family: 'Arial Normal', 'Arial';
      text-align: center;
      font-weight: bold;
      letter-spacing: 2px;
      font-size: 25px;
      width: 250px;
      line-height: 60px;
    }
    .el-input {
      margin-top: 10px;
    }
    /deep/ .el-input__inner {
      border-radius: 25px;
      background-color: #f3f5f9;
      border: none;
    }
    .el-input {
      height: 90%;
    }
  }
.el-submenu .el-menu-item{
  min-width: 75px;
}
.el-submenu .el-menu-item{
  padding: 0;
  text-align: center;
}
/deep/.el-submenu__title{
  padding: 0;
}
}
/deep/.el-badge__content.is-fixed {
  top: 30%;
}
.menu-i {
  color: orange;
  font-size: 25px;
}
/deep/.el-icon-arrow-down:before {
  display: none;
}
.el-menu-demo{
  display: flex;
}
.avatar {
  display: inline-block;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  margin-right: 10px;
}
.text-avatar{
       cursor: default;
       display: inline-block;
       width: 40px;
       height: 40px;
       text-align: center;
       background-color:orange;
       line-height: 40px;
       color: rgb(255, 255, 255);
       position: relative;
       border-radius: 50%;
     }
     .new-title{
       font-size: 18px;
     }
.el-main {
  background-color: #f0f2f5;
}
.el-aside {
  background-color: #cd853f;
}
// 实现页面淡入淡出
.component-fade-enter-active, .component-fade-leave-active {
  transition: opacity .3s ease;
}
.component-fade-enter, .component-fade-leave-to
/* .component-fade-leave-active for below version 2.1.8 */ {
  opacity: 0;
}
</style>
